<?php

use Phalcon\Mvc\Router;

$router = new Router();
//$router = new Router(false);
$router->removeExtraSlashes(true);  // 移除URL多余的斜杠
//$router->setUriSource(Router::URI_SOURCE_GET_URL);

$router->setDefaultController('index');
$router->setDefaultAction('index');
$router->setDefaultModule('frontend');
$router->setDefaultNamespace('Apps\Frontend\Controllers');

// APP API
$router->add('/appApi', [
        'module' => 'appApi',
        'namespace' => 'Apps\AppApi\Controllers\\',
        'controller' => 'index',
        'action' => 'index',
    ]
);
$router->add('/appApi' . '/:action', [
        'module' => 'appApi',
        'namespace' => 'Apps\AppApi\Controllers\\',
        'controller' => 'index',
        'action' => 1,
    ]
);

$defaultController = 'index';
$defaultAction = 'index';
$urlBase = [
    //'/appApi'   => ['module'=>'appApi', 'namespace'=>'Apps\AppApi\Controllers\\'],
    '/backend'  => ['module'=>'backend', 'namespace'=>'Apps\Backend\Controllers\\'],
    '/manage'   => ['module'=>'manage', 'namespace'=>'Apps\Manage\Controllers\\'],
    '/frontend' => ['module'=>'frontend', 'namespace'=>'Apps\Frontend\Controllers\\'],
    '/csoap'    => ['module'=>'csoap', 'namespace'=>'Apps\Csoap\Controllers\\'],
    '/pay'      => ['module'=>'pay', 'namespace'=>'Apps\Pay\Controllers\\'],
];

foreach($urlBase as $k=>$v) {
    $module = $v['module'];
    $namespace = $v['namespace'];
    $router->add($k . '/:params', [
        'module' => $module,
        'namespace' => $namespace,
        'controller' => $defaultController,
        'action' => $defaultAction,
        'params' => 1
    ]);

    $router->add($k . '/:controller/:params', [
        'module' => $module,
        'namespace' => $namespace,
        'controller' => 1,
        'action' => $defaultAction,
        'params' => 2
    ]);

    $router->add($k . '/:controller/:action/:params', [
        'module' => $module,
        'namespace' => $namespace,
        'controller' => 1,
        'action' => 2,
        'params' => 3
    ]);
}

return $router;